﻿<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Create Platform</title>

    <!-- Custom fonts for this template-->
    <link href="vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
    <link
        href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i"
        rel="stylesheet">

    <!-- Custom styles for this template-->
    <link href="css/sb-admin-2.min.css" rel="stylesheet">

</head>

<body class="bg-gradient-primary">

    <div class="container">

        <div class="card o-hidden border-0 shadow-lg my-5">
            <div class="card-body p-0">
                <!-- Nested Row within Card Body -->
                <div class="row"><img src="img/药品2.jpg" width="460" height="477" alt=""/>
<div class="col-lg-7">
            <div class="p-5">

                            <div class="text-center">
                                <h1 class="h4 text-gray-900 mb-4">Create a New Platform</h1>
                            </div>

                            <form class="user">

                                <div class="form-group">
                                    <input type="text" class="form-control " id="oname" onblur="is_oname_repeat(this.value)"
                                       placeholder="Platform Name">
                                </div>

                                <div class="form-group">
                                    <input type="text" class="form-control " id="omnemonics_code"
                                       placeholder="Mnemonic Code">
                                </div>

                                <div class="form-group row">
                                    <div class="col-sm-12" >	
                                        <select class="form-control" id="platform_type" >
                                            <option value ="volvo" hidden>--choose platform type--</option>
                                            <option>buyer</option>
                                            <option>seller</option>
                                            <option>manufacturer</option>                                          
                                        </select>  
                                    </div>
                                </div>    
                                
                               <br>
                               <button type="button" class="btn btn-success btn-block" id="submit">Submit</button>
                               <hr>
                            </form>

                            <div class="text-center">
                                <a class="small" href="login.html">Return to the Login Page</a>
                            </div>

                            <br>
                            <br>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>

    <!-- Bootstrap core JavaScript-->
    <script src="vendor/jquery/jquery.min.js"></script>
    <script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

    <!-- Core plugin JavaScript-->
    <script src="vendor/jquery-easing/jquery.easing.min.js"></script>

    <!-- Custom scripts for all pages-->
    <script src="js/sb-admin-2.min.js"></script>

    <script type="text/javascript">
        var url=decodeURI(location.href);
        var num=url.indexOf("?");
        var str=url.substr(num+1);
        //console.log(str);
    </script>

</body>

<!-- <script>
    $(function(){
        $('#submit').on("click",function(){
          var oname=$("#oname").val;
          var omnemonics_code=$("#omnemonics_code").val;
          var platform_type=$("#platform_type").val;
          console.log(oname);
          $.ajax({
            type:"get",
            dataType:"json",
            url:"http://rap2api.tao bao.org/app/mock/281919/check",          
            data:{
                "oname":oname,
                "omnemonics_code":omnemonics_code,
                "platform_type":platform_type
            },
            success:function(data){
                console.log(data);
                if(data.response=="true"){
                    alert("提交成功！请等待审核！");
                }
                else{
                    alert("提交失败！");
                }               
            }
          });
        });
    });
            
</script> -->

<script type="text/javascript">
    function is_oname_repeat(obj){
        console.log(obj);
        var oname=obj;
        $.ajax({
            type:"get",
            dataType:"json",
            url:"http://210.30.97.103:20305/register/platforms",
            data:{
                "oname":oname
            },
            success:function(data){
                console.log(data);
                if(data==true){
                    alert("名字已重复！请重新输入！");
                    document.getElementById("oname").value = '';
                }
              
            }
        });
    }
</script>

<script>
$(function(){
    $('#submit').on("click",function(){
    if($("#oname").val()==""){
        console.log("aa");
        alert("名称不能为空，请重新输入！");
    }
    else if($("#omnemonics_code").val()==""){
        alert("助记码不能为空，请重新输入！");
    }
    else if($("#platform_type").val()=="volvo"){
        alert("请选择平台类型！");
    }
    else{
        var addJson={
        "oname":$("#oname").val(),
        "omnemonics_code":$("#omnemonics_code").val(),
        "platform_type":$("#platform_type").val()       
        };
        console.log(addJson);
        ajax(addJson);
    }
    });
});

function ajax(obj){
    var url="http://210.30.97.103:20305/register/platforms";
    $.ajax({
        url:url,
        type: "put",
        data:{
            "oname":obj.oname,
            "omnemonics_code":obj.omnemonics_code,
            "type": obj.platform_type,
            "username": str
        },
        success:function(data){
            console.log(data);
            if(data==1){
                alert("提交成功！请等待审核！");
            }
            else{
                alert("提交失败！");
            }               
        }
    });
}
</script>



</html>